<?php

App::uses('Crud', 'Model');

class Answer extends Crud
{
    /**
     * Al Agregar/eliminar/actualizar las constantes de los modelos implica ir
     * y actualizar los comentarios en los campos de la tabla asociada a este modelo.
     */
    const STATUS_ENABLED = 1;
    const STATUS_DISABLED = 0;

    /**
     * Obtenemos los registros para el grid del admin
     * @return array
     */
    public function getEnabledBySource($sourceId) {
        $filters = array(
            'fields' => array(
                'description as text',
                'id as value',
                'image as img',
                'is_ok as ok'
            ),
            'conditions' => array(
                'status' => self::STATUS_ENABLED,
                'question_id' => $sourceId
            ),
            'order' => array(
                'id ASC'
            ),
        );
        $records = $this->find('all', $filters);
        return $this->flatArray($records);
    }
    
    public function getForQuestionExam($questionId) {
        $filters = array(
            'conditions' => array(
                'status' => self::STATUS_ENABLED,
                'question_id' => $questionId
            )
        );
        $records = $this->find('all', $filters);
        
        return $this->flatArray($records);
    }
    
}